Please use code box to answer questions


Write a complete C++ program, including comments (worth 2 pts--include a good comment at the top and at least one more good comment later in the program), to do the following:

The task is to create a program for a teacher. This program will read in a set of students and print an individualized report and a class report at the end of the program.





1. The program will read in the id number of the student and 4 integer test grades.


2. The program will compute the student’s average; which is the sum of the test scores divided by 4. If the student has an average of 95 or higher, the program will indicate that the student is on the honor roll. If the student scored below 70, the program will indicate that the student has failed the class.


3. If the student is not on the honor roll and did not fail, the program will throw out the lowest test score and calculate the average again. This average is the students “adjusted average.” This is the sum of the highest 3 scores divided by 3.



4. The letter grade will be printed based on the average using the following scale:

90 or more = A
80 to 90 = B
70 to 80 = C
Below 70 = F



6. Then the program should skip a few lines of output and repeat the entire series of steps for the next student, and so on, until the last person has been processed. You must decide how to recognize that the last person has been processed, and you must explain this in a comment.


7. At the end, print the total number of students processed, the number of students who failed and the number of students on the honor roll.


**//Vanessa Castillo**
#include <iostream>
#include <string>
 
using namespace std;
 
double gradeAvg(int, int, int, int);
double adjustedGradeAvg(int, int, int, int);
int minimumScore (int, int, int, int);
string CalculateLetterGrade(double);
 
int main()
 
{
    int studentId;
    int grade1, grade2, grade3, grade4 = 0;
    int totalStudents = 0;
    int totFailStudents = 0;
    int totHonorRollStudents = 0;
    double studentAvg;
 
    while ((totalStudents >= 0 && totalStudents < 10))
    //6. The program stops once there are 10 students
    //(assuming there are 10 students in class)
    {
        //1. Reads in Student ID and 4 test scores
        cout << "Enter 4-digit Student Id: ";
 
        cin >> studentId;
 
        cout << "Enter 4 test grades: ";
 
        cin >> grade1 >> grade2 >> grade3 >> grade4;
 
        studentAvg = gradeAvg(grade1, grade2, grade3, grade4);
 
        //2. Decide if student failed or is in honor roll
        if (studentAvg >= 95)
        {
            totHonorRollStudents ++;
            cout << "This student is on Honor Roll" << endl;
        }
        if (studentAvg < 70)
        {
            totFailStudents ++;
            cout << "This student has failed the class" << endl;
        }
 
        totalStudents ++;
 
        cout << "Student Grade Average: " << CalculateLetterGrade(studentAvg) <<" (" << studentAvg << ")" << endl << endl << endl;
 
    }
 
    //7. Prints total of students
    cout << "Total number of students processed: " << totalStudents << endl;
    cout << "Total number of students who failed: " << totFailStudents << endl;
    cout << "Total number of students on Honor Roll: " << totHonorRollStudents << endl;
 
 return 0;
}
 
double gradeAvg(int grade1, int grade2, int grade3, int grade4)
{
    //2. Calculate average of 4 test scores
    double avg = (grade1 + grade2 + grade3 + grade4) / 4.0;
 
        return avg;
}
 
double adjustedGradeAvg(int grade1, int grade2, int grade3, int grade4)
{
    //3. Calculate adjusted average if student did not fail and is not in honor roll
    int minGrade = minimumScore(grade1, grade2, grade3, grade4);
 
    double adjAvg = (grade1 + grade2 + grade3 + grade4 - minGrade) / 3.0;
 
        return adjAvg;
 
}
 
int minimumScore (int a, int b, int c, int d)
{
    //Get minimum grade
    int minSoFar;
 
    if (a < b)
        minSoFar = a;
    else
        minSoFar = b;
 
    if (minSoFar > c)
        minSoFar = c;
 
    if (minSoFar > d)
        minSoFar = d;
 
    return minSoFar;
}
 
string CalculateLetterGrade(double avg)
{
    string letterGrade;
    //4. Calculate letter grade
    if (avg >= 90)
        letterGrade = "A";
 
    if (avg >= 80 && avg < 90)
        letterGrade = "B";
 
    if (avg >= 70 && avg < 80)
        letterGrade = "C";
 
    if (avg < 70)
        letterGrade = "F";
 
    return letterGrade;
 
}
 

// Nadeen Elakkad
# include <iostream>
using namespace std;
int main ()
{
    int id,test1,test2,test3,test4,newscore;
    int studentprocessed=0, fail=0,honors=0;
    double avg,adavg;
 
    cout<<"enter ur id"<<endl;
    cin>>id;
 
    while (id>=0)
    {
        cout<<"enter your scores"<<endl;
        cin>>test1>>test2>>test3>>test4;
        avg=(test1+test2+test3+test4)/4.0;
        if (avg>=95)
        {
            cout<<"A   "<<"Honors"<<endl;
            honors++;
        }
        if(avg<95 && avg>70)
        {
            if (test1<test2)
                newscore=test1;
            else
                newscore= test2;
            if(newscore>test3)
                newscore=test3;
            if (newscore>test4)
                newscore=test4;
            adavg=(test1+test2+test3+test4-newscore)/3.0;
            cout<<"adjested average is "<<adavg<<endl;
        }
        if (avg<70)
        {
            cout<<"F      "<<"you failed"<<endl;
            fail++;
        }
        if (avg>=80 && avg<90)
            cout<<"B"<<endl;
        if (avg>=70 && avg<80)
            cout<<"C"<<endl;
        studentprocessed++;
        cout<<"Enter id or -1"<<endl;
        cin>>id;
    }
    cout<<"processed "<<studentprocessed<<" honors  "<<honors<<" fail"<<fail<<endl;
    return 0;
}
 




//chris Van Doren fall07midterm Q#1
//create a program for a teacher for student reporting
 
#include <iostream>
 
using namespace std;
 
int main()
 
{
 
int idnum, test1, test2, test3, test4, goOn, low, students, failed, honor;
double ave, adjAve;
 
cout<<"run program? 1 - yes, 2 - no :"<<endl;
cin>>goOn;//let's the program enter its main loop
students = 0;//total number of students processed in while loop variable
failed = 0;//total failed students variable
honor = 0;//total with honor roll variable
 
while (goOn==1)
    {
    students++;
    cout<<endl<<endl<<"enter student ID number :"<<endl;
    cin>>idnum;
    cout<<endl<<"enter the four test grades :"<<endl;
    cin>>test1>>test2>>test3>>test4;
    ave = (test1 + test2 + test3 + test4)/4.0;
 
    if (ave>=95)
        {
        cout<<"they're hon'or roll! Grade: A"<<endl;
        honor++;
        }
 
    if (ave<70)
        {
        cout<<"they've failed! Grade F"<<endl;
        failed++;
        }
 
    if (ave>=70 && ave<95)
        {
        low=test1;
        if (low>test2)
            low=test2;
        if (low>test3)
            low=test3;
        if (low>test4)
            low=test4;
 
        adjAve = (test1 + test2 + test3 + test4 - low)/3.0;
        //adjusted average of the test scores to that of the 3 best test scores
 
 
        if (adjAve>=90)
            cout<<"Grade: A"<<endl;
        if (adjAve>=80 && adjAve<90)
            cout<<"Grade: B"<<endl;
        if (adjAve>=70 && adjAve<80)
            cout<<"Grade: C"<<endl;
 
        }
 
 
    cout<<endl<<endl<<endl<<"continue entering students?";
    cout<<" 1 - yes, 2 - no :"<<endl;
    cin>>goOn;
    //this let's the program keep looping until the user is done
    }
 
cout<<endl<<endl<<"Total students: "<< students<< endl;
cout<<"Total Honor roll: "<< honor<< endl;
cout<<"Total failed: "<< failed<< endl;
 
return 0;
}




I Evaluate each of the following according to the C++ precedence rules. In each case, show what value is stored in the variable on the left-hand side. For each part, start from the original values.

SHOW YOUR WORK SO IT IS CLEAR WHICH OPERATION IS DONE FIRST, THEN SECOND, ETC., UNTIL THE FINAL ANSWER. DON’T SKIP STEPS.

int e = 7, b = 3, g = 5, h = 10;
double x = 1.5, r = 2.4;


(i) h = g – e / b * 2 - 1; h =


// Melikov, K.
// e/b = 2
// e/b*2 = 4
// g - e/b*2 = 1
// g - e/b*2 - 1 = 0
// h = 0

Nadeen Elakkad- Althea Dasilva
I. (i) Step1: 5-7/3*2-1
step2: 5-(7/3)*2-1
step3: 5-2*2-1
step4: 5-4-1
step5:H=0


h=5-7/3*2-1
h=5-2*2-1
h=5-4-1
h=1-1
h=0
 
**Alyssa Sheldon**

From : Steven Hernandez
 
First: (Division) {e/b} , so 7/3 = 2.
Second: (Multiply) {e/b * 2}, so 2*2 = 4.
Third: (Subtraction) {g-4}, so 5-4 = 1.
Fourth: (Subtraction) (g-4-1), so 1-1 = 0
Fifth: h= 0.
 





(ii) h = b * 10 – e % 2 / g; h =
// Melikov, K.
// b * 10 = 30
// e % 2 = 1
// e % 2 / g = 0
// b * 10 - e % 2 / g = 30
// h = 30

Nadeen Elakkad- Althea Dasilva
 
step1: 3*10-7%2/5
step2:(3*10)-7%2/5
step3:30-(7%2)/5
step4:30-(1/5)
step5: 30-0
step6: H=30

h=3*10-7%2/5
h=30-7%2/5
h=30-1/5
h=30-0
h=30
 
**Alyssa Sheldon**

From : Steven Hernandez
 
First: (Multiply) {b*10} , so 3*10 = 30.
Second: (Modulus) {e% 2}, so 7%2 = 1.
Third: (Division) { e% 2/g}, so 1/5 = 0.
Fourth: (Subtraction) , so 30-0 = 30.
Fifth: h= 30.
 



(iii) r = 1 - (double) e / b * g; r =
// Melikov, K.
// e / b = 2.333333
// e / b * g = 11.666667
// 1 - e / b * g = -10.666667
// r = -10.666667

Nadeen Elakkad- Althea Dasilva
 
step1: 1-7.0/3*5
step2: 1-(7.0/3)*5
step3:1-2.33333*5
step4: 1-(2.33333*5)
step5:1-11.6666
step6: -10.6666

r=1-(double)e/b*g
r=1-7.0/3*5
r=1-2.33333*5
r=1-11.6667
r=-10.6667
 
**Alyssa Sheldon**

From : Steven Hernandez
 
First: (Division) {double e/b} , so 7.0*3 = 2.33
Second: (Multiply) { double e/b * g}, so 2.33*5 = 11.67
Third: (Subtraction) , so 1- 11.67 =  -10.67
Fourth: r=  -10.67.
 





9 pts
II Each of the following independent segments has a number of compilation errors. Underline each compilation error, then rewrite each statement to the right so that all of these errors are fixed. Assume all variables have been declared.

You must rewrite each statement--do not omit any statements.


Do not change any complete statements or parts of statements that are already valid. Correct compilation errors only, nothing else.

1. cin << a; (>>)
while (a plus 1 is equal to b)

subtract 2 from a; a-2;
add 1 to b; 1+b;

//Nadeen Elakkad- Althea Dasilva
//cin>>a;
//while (a+1==b)
//a-2;
//b++;//
 

//Nusret Kokobobo
 
cin>>a;
while ( a + 1 == b )
{
    a -= 2;
    b++;
}





2. cout << 'nonzero'; "nonzero"
if x + y <= r / 3; enter and tab
3x = y + 5r
else
cout << t;
3 cout<<t<<3;

Nadeen Elakkad- Althea Dasilva
//"nonzero"
//if (x+y<=r/3)
//x=(y+5*r)/3;
//cout<<t;
 

//Nusret Kokobobo
 
cout<<"nonzero";
if ( x + y <= r / 3 )
   x = (y + 5 * r) / (x * 3 );
else
   cout<<t<<" 3 "<<t<<" 3 ";



20 pts
III a. Show exactly what is printed by the following program:

#include <iostream>
using namespace std;
int main()
{
int x = 12, y = 0, z = 0;

while (x >= y) {
cout << x << " " << y << endl;
x = x ‑ y;
y += 2;
if (y > 4)
z = z + y * 10;
else
z = z + 3;
cout << x << " " << y << " " << z << endl;
}
cout << x << endl << y;
cout << endl << z;
return 0;
}


12  0
12  2  3
12  2
10  4  6
10  4
6   6  66
6   6
0   8  146
0
8
146
 
By Indira, Zatarsha, Jasmine, Sapphira

From : Steven Hernandez
 
    12 0
    12 2 3
    12 2
    10 4 6
    10 4
    6 6 66
    6 6
    0 8 146
    0
    8
    146
 

12  0
12  2  3
12  2
10  4  6
10  4
6  6  66
6  6
0  8  146
0
8
146
Judah Sorscher



b. Show everything that is printed by the following program.
Assume that the data values shown below are typed in one at a time in response to the prompts: 14 78 25

#include <iostream>
using namespace std;
int const LIMIT = 3;
int main()
{
int x = 8, y = 7, j = 2, k = 2;

for (j = 1; j <= LIMIT; j++) {
k++;
cout << "type in a number" << endl;
if (k != 4)
cin >> y;
else
cin >> x;
if (j == 2)
k = 0;
cout << x << " " << y << " "
<< j << " " << k << endl;
}
cout << x << endl << y << " " << k;
return 0;
}
Nadeen Elakkad- Althea Dasilva
 
  OUTPUT:
8  14  1  3
8  78  2  0
8  25  3  1
8
25  1
 


Output:
14
8  14  1  3
78
78  14 2 0
25
78  25 3 1
78
25  1
 
By Indira, Zatarsha, Jasmine, Sapphira
 
 
 
 

From : Steven Hernandez
 
0UTPUT:
14
8  14  1  3
78
78  14  2  0
25
78 25 3 1
78
25 1
 


c. What would be printed if the third line of the program were changed to what is shown below (and everything else is the same)?



int const LIMIT = 0;

//Nadeen Elakkad-Althea dasilva
the loop would terminate and print the cout that is out side of the loop only.
OUTPUT
8
7 2

If the constant is zero it can’t run the for-loop because it would be less
than the initial value instead it would do everything that is on the outside
of the loop. In this case it would go to the print statement and print:
8
7 2
 
By Indira, Zatarsha, Jasmine, Sapphira
 


From : Steven Hernandez
 
If the third line is changed to int const LIMIT = 0; then the for loop will not even start because the test becomes false.  The statement after the loop is then printed so the OUTPUT is:
8
7 2
 

IV Show what is printed by the following program.

#include <iostream>
using namespace std;
int funny(int,int);
int main()
{
int a = 1, b = 4, c = 5;

c = funny(a,b);
cout << a << " " << b << " "
<< c << endl;

a = 0;
c = 8 * funny(6,a-1);
cout << a << " " << c << endl;

return 0;
}

int funny(int p, int q)
{
int r;

if (q < p)
r = 3 * q;
else
r = 7 * p;
cout << "funny: r is " << r << endl;
return r + p;
}


funny: r is 7
1 4 8
funny: r is -3
0 24
 
**Alyssa Sheldon**

/Nadeen Elakkad
funny: r is 7
1 4 8
funny: r is -3
0 24




11 pts
V a. Include a good comment when you write the function described below:

Write a function named findthemiddle, which receives 4 parameters. It determines the middle value by finding the largest value and the smallest value and averages the two values.

For example, if the input values are 5 3 8 1, the function sums 1 and 8, and divides by 2, to get 4.5.



//chris van doren   fall09 midterm review sheet Q#Va.
 
int findthemiddle (int a, int b, int c, int d)
{
double high, low, middle;
 
high = a;
if (b>high)
high = b;
if (c>high)
high = c;
if (d>high)
high = d;    //finds the high value
 
 
low = a;
if (b<low)
low = b;
if (c<low)
low = c;
if (d<low)
low = d;    //finds the low value
 
middle = (high + low)/2.0;  //finds the mid value
return middle;
}
 



//Nadeen Elakkad- Althea Dasilva
# include <iostream>
using namespace std;
double findthemiddle (int,int,int,int); //prototype
int main ()
{
    double z;
    int num1,num2,num3,num4;
    num1=5;
    num2=3;
    num3=8;
    num4=1;
 
    z=findthemiddle (num1,num2,num3,num4); //call the function
    cout<<"The Middle is: "<<z;
 
    return 0;
}
double findthemiddle (int a,int b,int c,int d)
{
     int minsofar,maxsofar;
     double avg;
 
     if (a<=b)
        minsofar=a;
     else
        minsofar=b;
     if (minsofar<=c)
         minsofar=minsofar;
     else
         minsofar=c;
     if(minsofar>d)
         minsofar=d;
 
     if (a>=b)
        maxsofar=a;
     else
        maxsofar=b;
     if (maxsofar>= c)
        maxsofar=maxsofar;
     else
        maxsofar=c;
     if (maxsofar< d)
        maxsofar=d;
 
     avg= (minsofar+maxsofar)/2.0;
     return avg;
}

















b. Show how to use the function findthemiddle in a main program.
The main program will store the answer returned by the function in a variable named z.

Give the call from a main program to this function.

In main, just call the function and print the answer returned.

NOTE: You should give the function prototype, the declaration for each of the variables mentioned above, and the call to the function and printing of the result; give nothing else in main.



//chris van doren   fall09 midterm review sheet Q#Vb.
#include <iostream>
using namespace std;
 
int findthemiddle(int, int, int, int);
 
int main()
 
{
int num1, num2, num3, num4;
double z;
cout<<"Give me 4 numbers and I'll find the middle value:"<<endl;
cin>>num1>>num2>>num3>>num4;
z = findthemiddle(num1, num2, num3, num4);
cout<<"The mid value is "<<z;
return 0;
}
 
 
 
 
int findthemiddle (int a, int b, int c, int d)
{
double high, low, middle;
 
high = a;
if (b>high)
high = b;
if (c>high)
high = c;
if (d>high)
high = d;    //finds the high value
 
 
low = a;
if (b<low)
low = b;
if (c<low)
low = c;
if (d<low)
low = d;    //finds the low value
 
middle = (high + low)/2.0;  //finds the mid value
return middle;
}
 















Explain the purpose of each function below.

int func1(int a, int b) Purpose:
{
if(a < b)
return a;
else return b;
}


Purpose:  Returns the smaller value of the two integers.
 
By Indira
 
 
 

Nadeen Elakkad- Althea Dasilva
 
returns minimum value

//  Garrett Tam
//  Tells me which number is the smaller of the two
 

// Melikov, K.
// Tells which number is smaller of the two.


//Nusret Kokobobo
 
finds lowest number

this function will return the smaller of two int values
Judah Sorscher



int func2(int a, int b) Purpose:
{
int c = 1;
for(int i = 0; i < b; i++)
c *= a;
return c;
}


Purpose:  (a) is multiplied by itself for (b) amount of times.
 
By Indira
 

//Nusret Kokobobo
 
'c' is multiplied by 'a', 'b' times



int func3(int a) Purpose:
{
if(a < 0)
return a;
else return (a*(-1));
}

Purpose:  Returns a positive or negative value of the same integer.
 
By Indira
 


Nadeen Elakkad- Althea Dasilva
determines if the number is negative if not, it makes it negative.

//Nusret Kokobobo
 
makes 'a' a negative number
 

this function will do the opposite of a absolute value function, instead of all ways
returning a positive it
will make the number or keep it negative, so a or -a = -a
judah sorscher
 


someone deleted the questions! DUH!
// Garrett Tam
// Finds the power of a to b-1.
// a^(b-1)
 

// Melikov, K.
// Give the additive inverse of the number if it's positive.
// Otherwise, just give the number.

int func3(int a) Purpose:
{
if(a < 0)
return a;
else return (a*(-1));
}
 
Garrett Tam
If a is negative it returns a.
If a is positive it returns the negative version of it.
double func4(int a, int b, int c, int d) Purpose:
{
return ((a+b+c+d)/4);
}
 


Purpose:  Returns the average of the integers.
 
By Indira
 

Melikov, K.
Find the average of four numbers.
bool func5(int a) Purpose:
{
if(a > 50)
return 1;
else return 0;
}
 

Purpose:  Returns True or False for the given.
 
By Indira
 

Melikov, K.
// Tells whether the number is greater than 50.
code